package Leetcode.LeetcodeDemo1;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

public class LeetCode45 {
    public static int jump(int[] nums) {
        int i=0;
        int maxIndex=0;
        int output=0;
        int k=0;
        while(true){
            int max=0;
            if(i==nums.length-1){
                break;
            }
            for(int j=i;j<=i+nums[i];j++){
                if(i+nums[i]>=nums.length-1){
                    k=nums.length-1;
                    break;
                }
                if(j+nums[j]>=max){
                    max=j+nums[j];
                    maxIndex=j;
                }
                k=maxIndex;
            }
            i=k;
            output++;
        }
        return output;
    }

    public static void main(String[] args) {
        int[] arr={3,2,1};
        Stack<String> stingStack=new Stack<String>();
        Queue<String> queue=new LinkedList<>();
        System.out.println(jump(arr));
    }
}
